package com.zhuanzhuan.hero.user.facade.label;

import com.bj58.spat.scf.server.contract.annotation.ServiceBehavior;
import com.bj58.youpin.common.rpc.result.Result;
import com.bj58.zhuanzhuan.zzentry.common.service.entity.ServiceHeaderEntity;
import com.bj58.zhuanzhuan.zzentry.common.service.entity.ZZOpenScfBaseResult;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZHeader;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZMethod;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZParam;
import com.zhuanzhuan.hero.user.dto.label.QueryUserBoundLabelDTO;
import com.zhuanzhuan.hero.user.dto.label.SaveUserBoundLevelLabelDTO;
import com.zhuanzhuan.hero.user.service.HeroUserInfoService;
import com.zhuanzhuan.hero.user.service.IUserManagementLabelService;
import com.zhuanzhuan.hero.user.util.ServiceHeaderUtil;
import com.zhuanzhuan.hero.user.vo.label.UserBoundLevelLabelVO;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @ClassName UserLabelFacadeImpl
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/24 14:32
 */
@ServiceBehavior
@Slf4j
public class UserLabelFacadeImpl implements IUserLabelFacade {

    @Resource
    private IUserManagementLabelService userLabelService;

    @Resource
    private HeroUserInfoService userInfoService;

    @ZZMethod(value = "queryUserBoundLevelLabel", desc = "查询经营标签", publicAccess = false)
    @Override
    public ZZOpenScfBaseResult<UserBoundLevelLabelVO> queryUserBoundLevelLabel(@ZZHeader ServiceHeaderEntity header,
        @ZZParam("param") @Valid QueryUserBoundLabelDTO queryUserBoundLabelDTO) {
        return ZZOpenScfBaseResult.buildSucc(userLabelService.queryUserBoundLevelLabel(ServiceHeaderUtil.parseUid(header),
            Integer.valueOf(queryUserBoundLabelDTO.getLabelType())));
    }

    @Override
    public Result<UserBoundLevelLabelVO> queryUserBoundLevelLabel(Long uid,
        @Valid QueryUserBoundLabelDTO queryUserBoundLabelDTO) {
        return Result.success(userLabelService.queryUserBoundLevelLabel(uid,
            Integer.valueOf(queryUserBoundLabelDTO.getLabelType())));
    }

    @ZZMethod(value = "saveUserBoundLevelLabel", desc = "保存经营标签", publicAccess = false)
    @Override
    public ZZOpenScfBaseResult<Boolean> saveUserBoundLevelLabel(@ZZHeader ServiceHeaderEntity header,
        @ZZParam("param") SaveUserBoundLevelLabelDTO saveUserBoundLevelLabelDTO) {
        Long uid = ServiceHeaderUtil.parseUid(header);
        userInfoService.checkCanEdit(uid);
        userLabelService.saveUserBoundLevelLabel(uid, saveUserBoundLevelLabelDTO, header);
        return ZZOpenScfBaseResult.buildSucc(true);
    }
}
